﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ATEGo
{
    public class Sm_CmdSuits : BJsonFile
    {
        public List<Sm_CmdTag> cmdSuits { get; set; }

        /// <summary>
        /// 根据cmdTagName找到对应的cmdTag
        /// </summary>
        /// <param name="cmdTagName"></param>
        /// <returns></returns>
        public Sm_CmdTag Get_cmdTag(string cmdTagName)
        {
            cmdTagName = cmdTagName.Trim();
            foreach (var item in cmdSuits)
            {
                if (item.cmdTag == cmdTagName)
                {
                    return item;
                }
            }
            return null;
        }

        /// <summary>
        /// 根据cmdTag的名字，找到对应的cmdTag
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [JsonIgnore]
        public Sm_CmdTag this[string cmdTagName]
        {
            get
            {
                return Get_cmdTag(cmdTagName);
            }
        }

        /// <summary>
        /// 返回cmdSuits的个数
        /// </summary>
        [JsonIgnore]
        public int Count
        { get { return cmdSuits.Count; } }

    }
    public class Sm_CmdTag
    {
        public string cmdTag { get; set; }

        public List<Sm_CmdDict> subCmds { get; set; }

        /// <summary>
        /// 返回命令的条数
        /// </summary>
        [JsonIgnore]
        public int Count
        { get { return subCmds.Count; } }

        [JsonIgnore]
        public Sm_CmdDict this[int index]
        {
            get
            {
                return subCmds[index];
            }
        }

        public Sm_CmdTag()
        {

        }
    }

    public class Sm_CmdDict:Dictionary<string,string>
    {
        [JsonIgnore]
        /// <summary>
        /// 默认的cmd
        /// </summary>
        public Sm_CmdDict Default_Cmd { get; set; }

        [JsonIgnore]
        public new string this[string key]
        {
            get
            {
                var result = base.TryGetValue(key, out var value);
                if (result)
                {
                    return value;
                }
                else
                {
                    return Default_Cmd[key];
                }
            }
            set
            {
                base[key] = value;
            }
        }
    }
}
